package com.luguokong.pet_rescue.service;


import com.luguokong.pet_rescue.mapper.UserMapper;
import com.luguokong.pet_rescue.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public int login(String phone, String password){
        int flag = 0;
        User user = userMapper.selectUserByPhone(phone);
        if(user != null && user.getPassword().equals(password)){
            flag = 1;
        }
        return flag;
    }

    public int registerUser(User user) {
        int flag = 0;
        User user1 = userMapper.selectUserByPhone(user.getPhone());
        if (user1 == null){
            flag = userMapper.insertUser(user);
        }
        return flag;
    }

    /**
     * 伪删除用户，修改 is_delete 为 1
     * @param user_id
     * @return int
     */
    public int deleteUserById(int user_id){
        User user = userMapper.selectUserById(user_id);
        user.setIsDelete(1);
        int i = userMapper.updateUserById(user);
        return i;
    }

    /**
     * 注销用户，强制删除
     * @param user_id
     * @return int
     */
    public int forceDeleteUserById(int user_id){
        int i = userMapper.deleteUserById(user_id);
        return i;
    }

    public int insertUser(User user){
        int i = userMapper.insertUser(user);
        return i;
    }

    public int updateUserById(User user){
        int i = userMapper.updateUserById(user);
        return i;
    }
    public User selectUserById(int user_id){
        User user = userMapper.selectUserById(user_id);
        return user;
    }
    public List<User> selectUserAll(){
        List<User> userList =  userMapper.selectUserAll();
        return userList;
    }
    public User selectUserByPhone(String phone){
        User user = userMapper.selectUserByPhone(phone);
        return user;
    }
//    爱心指数降序
    public List<User> selectUserByStarByAsc(){
        List<User> userList = userMapper.selectUserByStarByAsc();
        return userList;
    }

    public List<User> selectUserAllByPageNumByPageSize(int pageNum, int pageSize){
        List<User> userList = userMapper.selectUserAllByPageNumByPageSize(pageNum, pageSize);
        return userList;
    }

    public int selectDataCount(){
        int i = userMapper.selectDataCount();
        return i;
    }




}
